/*
 * @Description: 表格列配置
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2021-11-05 11:41:30
 * @LastEditTime: 2025-09-29 11:13:48
 */
import { defineTableCols } from "@/components/TablePage/predefined";
import { SexOpt } from "@/helpers/selection";
import { createTagVNode } from "@/helpers/createVNode";

export default defineTableCols(() => [
  {
    minWidth: 50,
    type: "selection",
    align: "center",
    fixed: "left",
  },
  {
    label: "用户id",
    minWidth: 140,
    prop: "id",
  },
  {
    label: "账号",
    minWidth: 120,
    prop: "username",
    showOverflowTooltip: true,
  },
  {
    label: "昵称",
    minWidth: 60,
    prop: "name",
  },
  {
    label: "性别",
    minWidth: 60,
    align: "center",
    prop: "sex",
    formatter: (_row, _column, cellValue: Sex) => {
      return cellValue ? SexOpt.getLabel(cellValue) : "/";
    },
  },
  {
    label: "角色",
    prop: "roles",
    minWidth: "200",
    formatter(_row, _column, cellValue) {
      if (!cellValue) {
        return "";
      }
      return cellValue.map((role: { name: string }) => {
        return createTagVNode(role.name, {
          type: "warning",
          effect: "plain",
        });
      });
    },
  },
  {
    label: "IP地址",
    minWidth: 110,
    prop: "ip",
  },
  {
    label: "登录地点",
    minWidth: "200",
    prop: "location",
    showOverflowTooltip: true,
  },
  {
    label: "登录时间",
    prop: "loginTime",
    minWidth: 160,
    sortable: true,
  },
  {
    label: "操作",
    fixed: "right",
    minWidth: 160,
    useRowBtns: ["detail"],
  },
]);
